<html>
<head><meta charset="utf-8"><title>return type in function · t-lang/project-never-type · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/index.html">t-lang/project-never-type</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html">return type in function</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237394252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237394252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237394252">(May 04 2021 at 20:40)</a>:</h4>
<p>hey <span class="user-mention" data-user-id="116009">@nikomatsakis</span> -- wondering if there's perhaps a quick answer here. When we're looking at some code like <code>foo(|| panic!())</code>, where foo takes <code>impl Fn() -&gt; B where B: Bar</code>, my assumption was that we would have an obligation <code>FnOnce::Output = ?R</code> <em>and</em> an obligation <code>?R: Bar</code>, but it looks like only the later is pending when we hit fallback</p>



<a name="237394337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237394337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237394337">(May 04 2021 at 20:41)</a>:</h4>
<p>I'm trying to figure out if it's because e.g. the FnOnce::Output = ?R obligation "always" holds, i.e., that we've already resolved it, or if I'm in somehow the wrong context or something</p>



<a name="237485709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237485709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237485709">(May 05 2021 at 12:23)</a>:</h4>
<p>hm ok so I've tracked down the obligation getting selected away:</p>
<div class="codehilite"><pre><span></span><code>    Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [_#0t, ()], item_def_id: DefId(2:3050 ~ core[2898]::ops::function::FnOnce::Output) }, _#1t), []), cause=ObligationCauseData { span: src/test/ui/never_type/fallback-trait-bound.rs:17:5: 17:22 (#0), body_id: HirId { owner: DefId(0:9 ~ fallback_trait_bound[317d]::main), local_id: 15 }, code: BindingObligation(DefId(0:6 ~ fallback_trait_bound[317d]::takes_closure_ret), src/test/ui/never_type/fallback-trait-bound.rs:9:26: 9:27 (#0)) }, param_env=ParamEnv { caller_bounds: [], reveal: UserFacing }, depth=0),
</code></pre></div>



<a name="237485811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237485811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237485811">(May 05 2021 at 12:24)</a>:</h4>
<p>which gets removed here <a href="https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L15">https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L15</a></p>



<a name="237486432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237486432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237486432">(May 05 2021 at 12:29)</a>:</h4>
<p>I guess it <em>is</em> already "just true", given the sized predicates and such...??</p>



<a name="237490357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237490357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237490357">(May 05 2021 at 13:00)</a>:</h4>
<p>I could try to store information just before that select but my impression it's generally considered fine to call it wherever, so we could easily regress (well, test suite would break)</p>



<a name="237490409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237490409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237490409">(May 05 2021 at 13:00)</a>:</h4>
<p>But it seems that's a bit unreliable</p>



<a name="237490821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237490821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237490821">(May 05 2021 at 13:02)</a>:</h4>
<p>Preventing the selection of this obligation seems pretty dangerous too though</p>



<a name="237491356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237491356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237491356">(May 05 2021 at 13:06)</a>:</h4>
<p>Maybe we should find the code that generates this obligation and stash some relationship information there, give we're going with a targeted approach</p>



<a name="237491404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237491404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237491404">(May 05 2021 at 13:06)</a>:</h4>
<p>I think for now I'll just stash information before select runs and that'll hopefully work well enough for a crater run at least</p>



<a name="237495077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237495077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237495077">(May 05 2021 at 13:31)</a>:</h4>
<p>alright that seems to have worked as expected, roughly</p>



<a name="237496565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237496565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237496565">(May 05 2021 at 13:41)</a>:</h4>
<p>hmm</p>



<a name="237496688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237496688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237496688">(May 05 2021 at 13:42)</a>:</h4>
<p>I imagine it gets selected because we just do a unification</p>



<a name="237497840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237497840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237497840">(May 05 2021 at 13:50)</a>:</h4>
<p>not sure I understand, since it seems like the relevant types to facilitate a unification in that obligation aren't known? Maybe we know enough for it to hold, though</p>



<a name="237498184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498184">(May 05 2021 at 13:52)</a>:</h4>
<p>You mean because we don't know <code>_#0t</code>?</p>



<a name="237498217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498217">(May 05 2021 at 13:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/259160-t-lang.2Fproject-never-type/topic/return.20type.20in.20function/near/237485811">said</a>:</p>
<blockquote>
<p>which gets removed here <a href="https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L15">https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L15</a></p>
</blockquote>
<p>is this the link you meant to send, <span class="user-mention" data-user-id="116122">@simulacrum</span> ?</p>



<a name="237498242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498242">(May 05 2021 at 13:53)</a>:</h4>
<p>oh I pushed since then</p>



<a name="237498261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498261">(May 05 2021 at 13:53)</a>:</h4>
<p><a href="https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L83">https://github.com/Mark-Simulacrum/rust/blob/never-type-fallback-new/compiler/rustc_typeck/src/check/fallback.rs#L83</a></p>



<a name="237498285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498285">(May 05 2021 at 13:53)</a>:</h4>
<p>but the whole loop there that's now visible is the thing I added as a hack</p>



<a name="237498713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498713">(May 05 2021 at 13:56)</a>:</h4>
<p>ah, that makes more sense =)</p>



<a name="237498779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498779">(May 05 2021 at 13:56)</a>:</h4>
<p>I am not 100% sure <span class="user-mention" data-user-id="116122">@simulacrum</span> why it gets selected away, I guess i have poke, it may be due to caching or other things</p>



<a name="237498804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498804">(May 05 2021 at 13:56)</a>:</h4>
<p>or it might be that <code>_#0t</code> is resolved but you're not seeing it in that print out :)</p>



<a name="237498809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498809">(May 05 2021 at 13:56)</a>:</h4>
<p>yeah, ultimately, may not matter for our experiments</p>



<a name="237498832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498832">(May 05 2021 at 13:56)</a>:</h4>
<p>_#0t is the closure type fwiw (obviously)</p>



<a name="237498882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498882">(May 05 2021 at 13:57)</a>:</h4>
<p>so it's sort of "somewhat known"</p>



<a name="237498952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237498952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237498952">(May 05 2021 at 13:57)</a>:</h4>
<p>and it may be enough to say that the output bound holds, because closures can return any sized type, and we know the output variable is sized</p>



<a name="237502222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237502222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237502222">(May 05 2021 at 14:17)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> is there a way to dump the hir or so with the type inference variables annotated? having to reconstruct what the numbers 'are' is a bit painful...</p>



<a name="237504180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237504180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237504180">(May 05 2021 at 14:30)</a>:</h4>
<p>so we have a new test case:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">future</span>::<span class="n">Future</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">ticker</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">loopify</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">loop</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="p">});</span><span class="w"></span>

<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">ticker</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">v</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(())</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">loopify</span><span class="o">&lt;</span><span class="n">F</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">F</span>::<span class="n">Output</span><span class="p">,</span><span class="w"> </span><span class="p">()</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">F</span>: <span class="nc">Future</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">loop</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="237504321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237504321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237504321">(May 05 2021 at 14:30)</a>:</h4>
<p>which fails with:</p>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
 --&gt; src/test/ui/never_type/fallback-future.rs:9:18
  |
9 |         Ok(v) =&gt; v,
  |                  ^ expected `()`, found `!`
  |
  = note: expected unit type `()`
                  found type `!`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
</code></pre></div>



<a name="237504554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237504554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237504554">(May 05 2021 at 14:32)</a>:</h4>
<p>I think what is happening is that the <code>return</code> in the match falls back to () as it 'leaks out' into live code, but by that point we've already decided that the loop {} should be !</p>



<a name="237504780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237504780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237504780">(May 05 2021 at 14:33)</a>:</h4>
<p>however, it's not clear to me <em>why</em> we decide that - I would expect that the inference variable for the async move output type is noticed in a F::Output = ?R obligation...</p>



<a name="237505114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237505114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237505114">(May 05 2021 at 14:35)</a>:</h4>
<p>hm, I wonder if the subtype predicates should be treated like coercion predicates for our purposes, in terms of checking whether something leaks out</p>



<a name="237507713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237507713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237507713">(May 05 2021 at 14:50)</a>:</h4>
<p>hm, ok, so subtype predicates do fix <em>this</em> test</p>



<a name="237507732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237507732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237507732">(May 05 2021 at 14:50)</a>:</h4>
<p>but they break src/test/ui/coercion/coerce-issue-49593-box-never.rs</p>



<a name="237508515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237508515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237508515">(May 05 2021 at 14:54)</a>:</h4>
<p>which... well, hm</p>



<a name="237508535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237508535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237508535">(May 05 2021 at 14:54)</a>:</h4>
<p>that test seems like it <em>should</em> fail, though it's a bit unclear</p>



<a name="237508627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237508627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237508627">(May 05 2021 at 14:55)</a>:</h4>
<p>I guess the intent is that Box::new(!) -&gt; Box&lt;dyn Error&gt; should work, even though in practice it <em>feels</em> like this is essentially a leak of never into 'userland'</p>



<a name="237525132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237525132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237525132">(May 05 2021 at 16:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/259160-t-lang.2Fproject-never-type/topic/return.20type.20in.20function/near/237502222">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> is there a way to dump the hir or so with the type inference variables annotated? having to reconstruct what the numbers 'are' is a bit painful...</p>
</blockquote>
<p>not really and yes it is :/</p>



<a name="237525155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237525155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237525155">(May 05 2021 at 16:27)</a>:</h4>
<p>at least, not that I know of</p>



<a name="237537153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237537153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237537153">(May 05 2021 at 17:46)</a>:</h4>
<p>hmm</p>



<a name="237537406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237537406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237537406">(May 05 2021 at 17:48)</a>:</h4>
<p>so I added the subtyping rule because my current understanding (unconfirmed by anything really) is in cases like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="n">o</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">o</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">e</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>we end up with a Subtype obligation on <code>return e</code> and <code>o</code> types</p>



<a name="237537853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237537853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237537853">(May 05 2021 at 17:51)</a>:</h4>
<p>which does fix the loopify test case above (<a href="https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/never_type/fallback-future.rs">https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/never_type/fallback-future.rs</a>)</p>



<a name="237537901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237537901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237537901">(May 05 2021 at 17:51)</a>:</h4>
<p>but we then run into trouble on code like in <a href="https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/coercion/coerce-issue-49593-box-never.rs#L13">https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/coercion/coerce-issue-49593-box-never.rs#L13</a></p>



<a name="237537930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237537930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237537930">(May 05 2021 at 17:51)</a>:</h4>
<p>where we actually <em>do</em> want ! to escape into live code without falling back to ()</p>



<a name="237538040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237538040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237538040">(May 05 2021 at 17:52)</a>:</h4>
<p>previously that worked because Niko's algorithm only considered explicit coercion sites, though I'm not sure why actually, since subtyping seems 'just as bad' to me - maybe because of this.</p>



<a name="237538412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237538412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237538412">(May 05 2021 at 17:55)</a>:</h4>
<p>the thing is, we derive the roots of the 'diverging' variable specifically from ! -&gt; Any adjustments</p>



<a name="237538531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237538531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237538531">(May 05 2021 at 17:55)</a>:</h4>
<p>but that seems <em>too</em> pessimistic</p>



<a name="237538549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237538549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237538549">(May 05 2021 at 17:56)</a>:</h4>
<p>maybe I should re-read Niko's gist again</p>



<a name="237540237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237540237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237540237">(May 05 2021 at 18:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/259160-t-lang.2Fproject-never-type/topic/return.20type.20in.20function/near/237537406">said</a>:</p>
<blockquote>
<p>so I added the subtyping rule because my current understanding (unconfirmed by anything really) is in cases like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="n">o</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">o</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">e</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>we end up with a Subtype obligation on <code>return e</code> and <code>o</code> types</p>
</blockquote>
<p>so it seems like I (or Niko's summary in the gist) is wrong about this claim:</p>
<blockquote>
<p>In a case like this, the type of the match is ultimately represented by a type variable ?M. The first arm is assigned a type variable ?T and the second arm (which panics) gets the type !. Both ?T and ! are coerced into ?M:</p>
</blockquote>



<a name="237578135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/237578135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#237578135">(May 05 2021 at 22:35)</a>:</h4>
<p>hm. I don't think I'll make much progress without some brainstorming session or so, seems like we need some insight to tease apart these two cases</p>



<a name="239426998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239426998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239426998">(May 19 2021 at 13:48)</a>:</h4>
<p>ok <span class="user-mention" data-user-id="116122">@simulacrum</span> sorry for dropping out here</p>



<a name="239427001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239427001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239427001">(May 19 2021 at 13:48)</a>:</h4>
<p>let me take a look at what you wrote...</p>



<a name="239427020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239427020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239427020">(May 19 2021 at 13:49)</a>:</h4>
<p>do you have a branch somewher I can look at?</p>



<a name="239427249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239427249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239427249">(May 19 2021 at 13:50)</a>:</h4>
<p>yeah</p>



<a name="239427313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239427313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239427313">(May 19 2021 at 13:50)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/84573">https://github.com/rust-lang/rust/pull/84573</a></p>



<a name="239427790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239427790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239427790">(May 19 2021 at 13:53)</a>:</h4>
<p>ah, ok</p>



<a name="239428134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428134">(May 19 2021 at 13:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/259160-t-lang.2Fproject-never-type/topic/return.20type.20in.20function/near/237537901">said</a>:</p>
<blockquote>
<p>but we then run into trouble on code like in <a href="https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/coercion/coerce-issue-49593-box-never.rs#L13">https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/src/test/ui/coercion/coerce-issue-49593-box-never.rs#L13</a></p>
</blockquote>
<p>so, in this case, we want <code>!</code> before <code>(): Error</code> is not true?</p>



<a name="239428243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428243">(May 19 2021 at 13:56)</a>:</h4>
<p>I actually think my algorithm ought to have handled that case--</p>



<a name="239428258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428258">(May 19 2021 at 13:56)</a>:</h4>
<p>even with a coercion</p>



<a name="239428313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428313">(May 19 2021 at 13:56)</a>:</h4>
<p>in particular, I the type variable there should only have been <em>targeted</em> by a "subtype/coercion from <code>!</code>"</p>



<a name="239428361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428361">(May 19 2021 at 13:57)</a>:</h4>
<p>hm</p>



<a name="239428379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428379">(May 19 2021 at 13:57)</a>:</h4>
<p>and I thought that was the criteria under which we would fall back to <code>!</code>-- that is, so long as you don't target anything which was <em>also</em> the target of a coercion from "live" variables</p>



<a name="239428400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428400">(May 19 2021 at 13:57)</a>:</h4>
<p>but I maybe have to look back at what I wrote :)</p>



<a name="239428671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428671">(May 19 2021 at 13:59)</a>:</h4>
<p>in the loopify example, is the what behavior do you <em>want</em> -- <code>()</code>?</p>



<a name="239428704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428704">(May 19 2021 at 13:59)</a>:</h4>
<p>I'm actually surprised that needs fallback at all</p>



<a name="239428745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428745">(May 19 2021 at 13:59)</a>:</h4>
<p>though I think I can imagine why</p>



<a name="239428855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428855">(May 19 2021 at 14:00)</a>:</h4>
<p>(but to be sure I understand, the problem was that you were falling back to <code>!</code> and getting a type error?)</p>



<a name="239428860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428860">(May 19 2021 at 14:00)</a>:</h4>
<p>I'm not sure -- I think ideally you'd have <code>!</code> in the sense that you aren't going to hit that code</p>



<a name="239428924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428924">(May 19 2021 at 14:00)</a>:</h4>
<p>and we do get <code>!</code>, but then that ran into problems with the type error</p>



<a name="239428962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239428962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239428962">(May 19 2021 at 14:01)</a>:</h4>
<p>it's not obvious what you would prefer, indeed</p>



<a name="239429000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429000">(May 19 2021 at 14:01)</a>:</h4>
<p>but the general rule is that we try to "coerce" <code>!</code> to make type errors go away</p>



<a name="239429048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429048">(May 19 2021 at 14:01)</a>:</h4>
<p>it's a bit surprising then that we are hitting a type error</p>



<a name="239429087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429087">(May 19 2021 at 14:01)</a>:</h4>
<p>I think adding the subtype rule to the coercion graph - <a href="https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/compiler/rustc_typeck/src/check/fallback.rs#L458">https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/compiler/rustc_typeck/src/check/fallback.rs#L458</a> solved that problem</p>



<a name="239429233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429233">(May 19 2021 at 14:02)</a>:</h4>
<p>trying to rerun tests now locally</p>



<a name="239429315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429315">(May 19 2021 at 14:02)</a>:</h4>
<p>interesting, ok</p>



<a name="239429425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429425">(May 19 2021 at 14:03)</a>:</h4>
<p>I do agree that subtyping / coercion probably ought not to be distinguished</p>



<a name="239429501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239429501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239429501">(May 19 2021 at 14:03)</a>:</h4>
<p>(I think the reason is that match arms can subtype to the 'match expression type', but don't coerce, but I didn't actually manage to confirm that)</p>



<a name="239430303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239430303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239430303">(May 19 2021 at 14:08)</a>:</h4>
<p>I could imagine it happens sometimes, but match usually converges</p>



<a name="239430358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239430358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239430358">(May 19 2021 at 14:08)</a>:</h4>
<p>coerces you mean?</p>



<a name="239430423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239430423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239430423">(May 19 2021 at 14:09)</a>:</h4>
<p>yeah the latest branch is only failing the box-never test:</p>
<div class="codehilite"><pre><span></span><code>error[E0277]: the trait bound `(): std::error::Error` is not satisfied
  --&gt; /home/mark/Build/rust/src/test/ui/coercion/coerce-issue-49593-box-never.rs:13:53
   |
LL |     /* *mut $0 is coerced to Box&lt;dyn Error&gt; here */ Box::&lt;_ /* ! */&gt;::new(x)
   |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
   |
   = note: required for the cast to the object type `dyn std::error::Error`
</code></pre></div>



<a name="239431514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239431514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239431514">(May 19 2021 at 14:15)</a>:</h4>
<div class="codehilite"><pre><span></span><code>DEBUG rustc_typeck::check::fallback create_coercion_graph: coercion_edges=[(_#1t, _#4t)]
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: diverging_type_vars={_#2t}
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: diverging_roots={_#4t}
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: unsolved_vid=_#1t root_vid=_#1t diverges=false
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: unsolved_vid=_#2t root_vid=_#4t diverges=true
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: root_vid=_#4t reaches [_#4t]
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: unsolved_vid=_#4t root_vid=_#4t diverges=true
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: root_vid=_#4t reaches [_#4t]
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: roots_reachable_from_diverging={_#4t}
DEBUG rustc_typeck::check::fallback calculate_diverging_fallback: roots_reachable_from_non_diverging={_#1t, _#4t}
</code></pre></div>



<a name="239431753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239431753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239431753">(May 19 2021 at 14:16)</a>:</h4>
<p>I think _#2t is the _ in Box&lt;_&gt;, perhaps?</p>



<a name="239431967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239431967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239431967">(May 19 2021 at 14:18)</a>:</h4>
<p>4t is the x, I suspect, not really sure what the 1t is though</p>



<a name="239432043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239432043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239432043">(May 19 2021 at 14:18)</a>:</h4>
<p>it doesn't really seem obvious that these should need any fallback in this code, so maybe something else is off</p>



<a name="239432389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239432389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239432389">(May 19 2021 at 14:20)</a>:</h4>
<p>hm, ok, so the problem I <em>think</em> is that Box::new(!) creates fallback on the type of the box, because for some reason it's not directly known from ! -- that seems like a bug almost? <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="239432492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239432492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239432492">(May 19 2021 at 14:21)</a>:</h4>
<p>i.e., we produce Box&lt;_&gt;, and since _ there touches live code, it falls back to (), and then we coerce ! -&gt; (), and wind up trying to do (): dyn Error, which isn't going to work</p>



<a name="239432858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239432858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239432858">(May 19 2021 at 14:23)</a>:</h4>
<p>so really we sort of want to say that in the case of coercion/subtyping from <em>known</em> !, then we shouldn't be falling back to ()</p>



<a name="239432874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239432874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239432874">(May 19 2021 at 14:23)</a>:</h4>
<p>but I don't know how feasible it is</p>



<a name="239502712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239502712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239502712">(May 19 2021 at 22:07)</a>:</h4>
<p>hmm</p>



<a name="239502768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239502768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239502768">(May 19 2021 at 22:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/259160-t-lang.2Fproject-never-type/topic/return.20type.20in.20function/near/239432858">said</a>:</p>
<blockquote>
<p>so really we sort of want to say that in the case of coercion/subtyping from <em>known</em> !, then we shouldn't be falling back to ()</p>
</blockquote>
<p>yeah, this came up before</p>



<a name="239502793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239502793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239502793">(May 19 2021 at 22:08)</a>:</h4>
<p>i.e., the regression that made us revert <code>!</code> before was like this</p>



<a name="239502803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239502803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239502803">(May 19 2021 at 22:08)</a>:</h4>
<p>and it is what motivated my original algorithm</p>



<a name="239502815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239502815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239502815">(May 19 2021 at 22:08)</a>:</h4>
<p>I don't <em>quite</em> understand what's going on yet</p>



<a name="239556541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239556541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239556541">(May 20 2021 at 08:57)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> so the test in question is ui/coercion/coerce-issue-49593-box-never.rs right?</p>



<a name="239556556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239556556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239556556">(May 20 2021 at 08:57)</a>:</h4>
<p>(Yes)</p>



<a name="239556779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239556779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239556779">(May 20 2021 at 08:59)</a>:</h4>
<p>is it possible you haven't pushed your latest commits?</p>



<a name="239560079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239560079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239560079">(May 20 2021 at 09:27)</a>:</h4>
<p>I'm digging into this code. If I'm not mistaken, <span class="user-mention" data-user-id="116122">@simulacrum</span>, this failure may be the result of a fairly surprising bug</p>



<a name="239560254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239560254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239560254">(May 20 2021 at 09:28)</a>:</h4>
<p>also damn my kingdom for the ability to jump in a debugging at any given point in the output and use <code>rr</code></p>



<a name="239560283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239560283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239560283">(May 20 2021 at 09:29)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> does this actually work and I'm just making my life harder than it has to be? <span aria-label="point up" class="emoji emoji-1f446" role="img" title="point up">:point_up:</span></p>



<a name="239560319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239560319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239560319">(May 20 2021 at 09:29)</a>:</h4>
<p>I think in this case I'd have been happy just to find the filename/line-number and not even have needed the ability to see the values of local variables</p>



<a name="239562789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239562789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239562789">(May 20 2021 at 09:51)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> so <a href="https://github.com/rust-lang/rust/blob/0eb4e811915eae2964e6072086d4a13c8daf136b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs#L1458">this line</a> should be a call to <code>eq</code>, I'm pretty sure:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">            </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">.</span><span class="n">misc</span><span class="p">(</span><span class="n">span</span><span class="p">),</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">param_env</span><span class="p">).</span><span class="n">eq</span><span class="p">(</span><span class="n">impl_ty</span><span class="p">,</span><span class="w"> </span><span class="n">self_ty</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>



<a name="239562823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239562823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239562823">(May 20 2021 at 09:51)</a>:</h4>
<p>however, I can't <em>quite</em> get a test that shows the current logic is unsound yet.</p>



<a name="239562841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239562841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239562841">(May 20 2021 at 09:51)</a>:</h4>
<p>What is happening here, as best I understand:</p>



<a name="239563021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239563021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239563021">(May 20 2021 at 09:53)</a>:</h4>
<ul>
<li>we are referencing a fully qualified method like <code>SomeType::&lt;X&gt;::foo</code></li>
<li>here <code>self_ty</code> is the type the user gave (<code>SomeType&lt;X&gt;</code>)</li>
<li>there is an impl like <code>impl&lt;A&gt; SomeType&lt;A&gt;</code> and <code>impl_ty</code> is <code>SomeType&lt;A&gt;</code></li>
<li>the code <em>as written</em> is requiring that <code>self_ty &lt;: impl_ty</code></li>
<li>but we want them to be the <em>same type</em></li>
</ul>



<a name="239563619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239563619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239563619">(May 20 2021 at 09:58)</a>:</h4>
<p>it may be that we can't trigger an unsoundness here because of the details of how this stuff works, but that seems surprising to me</p>



<a name="239563647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239563647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239563647">(May 20 2021 at 09:58)</a>:</h4>
<p>it feels like this should allow the type <em>written by the user</em> to be different than the type that shows up in the fn signature</p>



<a name="239563659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239563659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239563659">(May 20 2021 at 09:58)</a>:</h4>
<p>in ways that are unexpected</p>



<a name="239564072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239564072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239564072">(May 20 2021 at 10:01)</a>:</h4>
<p>if I change to <code>eq</code>, the test passes</p>



<a name="239573130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239573130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239573130">(May 20 2021 at 11:19)</a>:</h4>
<p>Huh!</p>



<a name="239573760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239573760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239573760">(May 20 2021 at 11:24)</a>:</h4>
<p>Well I guess seems good that we found it, and then I'll check some more of the crater breakage in as explicit test cases</p>



<a name="239585596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239585596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239585596">(May 20 2021 at 12:54)</a>:</h4>
<p>I'm still poking at trying to make a test case that shows my this is wrong</p>



<a name="239585614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239585614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239585614">(May 20 2021 at 12:54)</a>:</h4>
<p>but yes</p>



<a name="239598350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598350">(May 20 2021 at 14:14)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> fwiw <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/wf/wf-static-method.rs#L50">https://github.com/rust-lang/rust/blob/master/src/test/ui/wf/wf-static-method.rs#L50</a> now fails with an error</p>



<a name="239598387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598387">(May 20 2021 at 14:14)</a>:</h4>
<p>lol</p>



<a name="239598399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598399">(May 20 2021 at 14:14)</a>:</h4>
<p>which, according to the comment, is right</p>



<a name="239598411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598411">(May 20 2021 at 14:14)</a>:</h4>
<p>ther looks like the kind of problem I was trying to setup</p>



<a name="239598450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598450">(May 20 2021 at 14:14)</a>:</h4>
<p>but I haven't quite gotten the pieces in the right shape</p>



<a name="239598505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598505">(May 20 2021 at 14:15)</a>:</h4>
<p>ah yes duh</p>



<a name="239598539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598539">(May 20 2021 at 14:15)</a>:</h4>
<p>I was doing that same pattern but with <code>'b = 'static</code></p>



<a name="239598549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598549">(May 20 2021 at 14:15)</a>:</h4>
<p>and of course then the code was ok</p>



<a name="239598563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598563">(May 20 2021 at 14:15)</a>:</h4>
<p>because <code>'static: 'a</code> for all <code>'a</code></p>



<a name="239598579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598579">(May 20 2021 at 14:15)</a>:</h4>
<p>that was as far as I got :)</p>



<a name="239598591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598591">(May 20 2021 at 14:15)</a>:</h4>
<p>anyway, yes, that should be an error</p>



<a name="239598620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598620">(May 20 2021 at 14:15)</a>:</h4>
<p>you should open a PR with just that one change and <code>r?</code> me</p>



<a name="239598639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598639">(May 20 2021 at 14:15)</a>:</h4>
<p>will do</p>



<a name="239598648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239598648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239598648">(May 20 2021 at 14:15)</a>:</h4>
<p>thanks :)</p>



<a name="239600730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239600730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239600730">(May 20 2021 at 14:27)</a>:</h4>
<p>filed <a href="https://github.com/rust-lang/rust/pull/85511">https://github.com/rust-lang/rust/pull/85511</a>, will cherry-pick it onto my branch in the meantime so I can continue making progress</p>



<a name="239663939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/259160-t-lang/project-never-type/topic/return%20type%20in%20function/near/239663939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/259160-t-lang/project-never-type/topic/return.20type.20in.20function.html#239663939">(May 20 2021 at 21:42)</a>:</h4>
<p>great, r+'d</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>